package cn.edu.imau.zy.examination.controller;


import cn.edu.imau.zy.common.auth.annotation.HasPermissions;
import cn.edu.imau.zy.common.core.entity.system.Districts;
import cn.edu.imau.zy.common.log.annotation.OperLog;
import cn.edu.imau.zy.common.log.enums.BusinessType;
import cn.edu.imau.zy.common.utils.poi.ExcelUtil;
import cn.edu.imau.zy.examination.domain.ElRepo;
import cn.edu.imau.zy.examination.service.IElRepoService;
import cn.hutool.core.util.IdUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import cn.edu.imau.zy.common.core.domain.R;
import cn.edu.imau.zy.common.core.controller.BaseController;

import java.util.Date;
import java.util.List;


/**
 * 题库 提供者
 * 
 * @author xsc
 * @date 2021-05-07
 */
@RestController
@RequestMapping("elrepo")
public class ElRepoController extends BaseController
{
	
	@Autowired
	private IElRepoService elRepoService;
	
	/**
	 * 查询
	 */
	@GetMapping("get/{id}")
	public ElRepo get(@PathVariable("id") String id)
	{
		return elRepoService.getById(id);
	}

	/**
	 * 查询
	 */
	@GetMapping("queryElRepo")
	public R queryElRepo(ElRepo elRepo)
	{
//		return elRepoService.queryElRepo(elRepo);
		return R.ok().put("data",elRepoService.queryElRepo(elRepo));
	}

	/**
	 * 查询题库
	 * @return
	 */
	@GetMapping("getQuName")
	public R getQuName(){
		return result(elRepoService.getQuNameList());
	}

	
	/**
	 * 查询题库列表
	 */
	@GetMapping("list")
	public R list(ElRepo elRepo)
	{
		startPage();
        return result(elRepoService.queryList(elRepo));
	}
	
	
	/**
	 * 新增保存题库
	 */
	@PostMapping("save")
	public R addSave(@RequestBody ElRepo elRepo)
	{
		elRepo.setCreateTime(new Date());
		elRepo.setUpdateTime(new Date());
		elRepo.setCode(IdUtil.getSnowflake(1,1).nextIdStr());
		return toAjax(elRepoService.save(elRepo));
	}

	/**
	 * 修改保存题库
	 */
	@PostMapping("update")
	public R editSave(@RequestBody ElRepo elRepo)
	{
		elRepo.setUpdateTime(new Date());
		return toAjax(elRepoService.updateByCode(elRepo));
	}
	
	/**
	 * 删除
	 */
	@PostMapping("remove")
	public R remove(String ids)
	{		
		return toAjax(elRepoService.removeById(ids));
	}



}
